<template>
	<view>
		<u-navbar :is-back="true" :is-fixed="true" title="基础信息"></u-navbar>
		<scroll-view scroll-y scroll-with-animation style="height: calc(100vh - 50px);" :show-scrollbar="false">
			<view class="pb-15">
				<free-divider></free-divider>
				<free-list-item title="营业执照" :showRight="false" :showLeftIcon="false" @click="update('navatar')">
					<free-avater slot="right" :src="user.navatar" size="100"
						style="width: 100px; height: 80px;"></free-avater>
				</free-list-item>
				<u-field v-model="mobile" label="企业名称" input-align="right" :field-style="placeholderStyle"></u-field>
				<u-field v-model="mobile" label="手机号" :disabled="true" input-align="right"></u-field>

				<u-field v-model="mobile" label="统一社会信用代码" label-width="230" input-align="right"
					:field-style="placeholderStyle"></u-field>

				<u-field v-model="mobile" label="注册资本" input-align="right" :field-style="placeholderStyle"></u-field>

				<u-field v-model="mobile" label="类型" input-align="right" :field-style="placeholderStyle"></u-field>

				<u-field v-model="mobile" label="法定代表人" label-width="180" input-align="right"
					:field-style="placeholderStyle"></u-field>

				<u-field v-model="mobile" label="成立日期" input-align="right" :field-style="placeholderStyle"></u-field>

				<u-field v-model="mobile" label="营业期限" input-align="right" :field-style="placeholderStyle"></u-field>

				<u-field v-model="mobile" label="主体地址" input-align="right" :field-style="placeholderStyle"></u-field>

				<u-field v-model="mobile" label="经营范围" input-align="right" :field-style="placeholderStyle"></u-field>

				<u-field v-model="mobile" label="注册时间" input-align="right" :field-style="placeholderStyle"></u-field>

			</view>
			<ferrButton title="编辑信息" @click="click"></ferrButton>
		</scroll-view>

	</view>
</template>

<script>
	import freeListItem from "@/components/free-ui/free-list-item.vue";
	import freeAvater from "@/components/free-ui/free-avater.vue";
	import freeDivider from "@/components/free-ui/free-divider.vue";
	import ferrButton from "@/components/free-ui/ferr-button.vue";
	import $H from '@/common/free-lib/request.js';
	import $U from "@/common/free-lib/util.js";

	export default {
		components: {
			freeListItem,
			freeAvater,
			freeDivider,
			ferrButton,
		},
		data() {
			return {
				user: {
					abnormal:'',
					address:'',
					agricultureLabel:'',
					avatar:'',
					businessEndTerm:'',
					businessLicense:'',
					businessStartTerm:'',
					businessTerm:'',
					buyScope:'',
					createTime:'',
					enterpriseName:'',
					followUserId:'',
					foundedTime:'',
					id:'',
					isFollow:'',
					legalRepresentative:'',
					natureBusiness:'',
					phone:'',
					registeredCapital:'',
					serviceCode:'',
					state:'',
					token:'',
					type:'',
					unifiedCreditCode:'',
					userType:'',
					username:'',
				},

				mobile: '测试奢侈',
				placeholderStyle: {
					color: '#999'
				}
			}
		},
		computed: {

		},
		methods: {
			update(key) {
				switch (key) {
					case 'navatar':
						uni.chooseImage({
							count: 1,
							sizeType: ['compressed'],
							success: (res) => {
								// 上传
								this.user.navatar = res.tempFilePaths[0]
							}
						})
						break;
					default:
						this.confirmType = key
						this.confirmText = this.user[key]
						this.$refs.confirm.show((close) => {
							if (this.confirmText === '') {
								return uni.showToast({
									title: "不能为空",
									icon: 'none'
								})
							}
							this.user[key] = this.confirmText
							uni.showToast({
								title: "修改成功",
								icon: 'none'
							})
							close()
						})
						break;
				}
			},

			openCode() {
				uni.navigateTo({
					url: '/pages/my/code/code'
				})
			},
			click(){
				console.log('--------')
			},
			getUserInfo(){
				uni.showLoading({
					title: '加载中'
				});
				$H.get(
					"/brand/user/queryById", {
						id,
					}, {}
				).then((res) => {
					if (!res.result) {
						uni.showToast({
							title: "未查询到相关信息",
							icon: "none",
						});
						return;
					}
					this.user.abnormal = res.result.abnormal;
					this.user.address = res.reult.address;
					this.user.agricultureLabel = res.reult.agricultureLabel;
					this.user.avatar = res.reult.avatar;
					this.user.businessEndTerm = res.reult.businessEndTerm;
					this.user.businessLicense = res.reult.businessLicense;
					this.user.businessStartTerm = res.reult.businessStartTerm;
					this.user.businessTerm = res.reult.businessTerm;
					this.user.buyScope = res.reult.buyScope;
					this.user.createTime = res.reult.createTime;
					this.user.enterpriseName = res.reult.enterpriseName;
					this.user.followUserId = res.reult.followUserId;
					this.user.foundedTime = res.reult.foundedTime;
					this.user.id = res.reult.id;
					this.user.isFollow = res.reult.isFollow;
					this.user.legalRepresentative = res.reult.legalRepresentative;
					this.user.natureBusiness = res.reult.natureBusiness;
					this.user.phone = res.reult.phone;
					this.user.registeredCapital = res.reult.registeredCapital;
					this.user.serviceCode = res.reult.serviceCode;
					this.user.state = res.reult.state;
					this.user.token = res.reult.token;
					this.user.type = res.reult.type;
					this.user.unifiedCreditCode = res.reult.unifiedCreditCode;
					this.user.userType = res.reult.userType;
					this.user.username = res.reult.username;
					uni.hideLoading();
				}).catch(error=>{
					console.error('请求出错', error); // 处理任何错误
					uni.showToast({
							title: "查询错误",
							icon: "none",
						});
					uni.hideLoading();
				})

			}
		}
	}
</script>

<style lang="scss" scoped>
	.u-border-bottom:after {
		border-bottom: 2px solid #dee2e6 !important;

	}
</style>